<title>偷梁换柱</title>
<meta charset="UTF-8"/>
<iframe src="index.html"  style="position: absolute;right:0;top:1%;min-height: 300px;border-width: 0px">
</iframe>
<h1>2.偷梁换柱--伪装请求</h1>
<xmp>
    在一些网站中，可以看到使用了xhr请求了求解，模拟xhr可以直接拿到接口返回数据抓取,添加如
    <script id="js_result" class="order_input" type="application/json">'+xhr.responseText+'</script>
    即id="js_result"的dom节点设置结果
</xmp>
<h1>
    示例
</h1>
<xmp  style="background:#f0f0f0;white-space: pre;text-align: left" >
        $url="https://www.dhl.de/de/toolbar/errors/fehlermeldung.html?".time();

        $api_url = "https://www.dhl.de/int-verfolgen/data/search?piececode=$finalNo&inputSearch=fasle&language=en";

        $get_content ="";
        $result =[];
        $header =[];

        $op = [
            "timeout"=>120 , //超时时间
           // "selector"=>"#shipmentnumber-single",//等待css选择器
            "selector"=>".main",//等待css选择器
            "debug"=>0,
            "input"=>'#shipmentnumber-single',
            "button"=>'.searchSubmit',
            'reuse'=>1,
            'wno'=>$finalNo
        ];
        $op['prejs'][]="ListenUrl:int-verfolgen>".$finalNo;
        $op['prejs'][]="document.getElementById('js_result').outerHTML='';";
        //$op['js'][]="Sleep:1";
        $op['js'][]=<<<JS

           function sendData() {
             var xhr = new XMLHttpRequest();
xhr.open('GET', "$api_url");
xhr.withCredentials = true;
xhr.onload = function() {
 if (xhr.status === 200) {

     console.log("resend done")
     if (xhr.responseText.indexOf('sendungen')>0){
            console.log("resend ok")
            window.document.body.innerHTML +='<script id="js_result" class="order_input"
                                                      type="application/json">'+xhr.responseText+'</script>';
     } else{
           console.log(xhr.responseText)
            setTimeout(function() {
                sendData();
         },20000)
     }

 }else{
        console.log(xhr.responseText)
            setTimeout(function() {
                sendData();
         },20000)
 }

};
xhr.send();
}
    console.log(1111);
sendData();
JS;
    $op['js'][]="Sleep:5";
        $op['js'][]=<<<JS
        if (window.document.body.innerHTML.indexOf("sendungen")>0){
            document.getElementsByTagName("pre")[0].id="js_result"
        }
JS;
    //固定页面请求
     $func ="HostGet";
    $tmp = HttpClient::RpcChromedpGet($url,$header,$op,$ip,$port,$ua_str,$func);
</xmp>